#include "client_service_view.h"

ClientService service;
//菜单
void ClientServiceView::menu(void)
{
	while(1)
	{
		system("clear");
		cout << "[1]预定图书" << endl;
		cout << "[2]查看个人信息" << endl;
		cout << "[3]查询图书信息" << endl;
		cout << "[4]浏览所有图书" << endl;
		cout << "[5]我的书单" << endl;
		cout << "[q]退出登录" << endl;
		cout << "[0]退出系统" << endl;
		switch(getch())
		{
            case '1' : reserveBook();break;
			case '2' : queryUser();break;
			case '3' : queryBook();break;
			case '4' : listAllBook();break;
			case '5' : myBookList();break;
			case 'q' : return;
			case '0' : exit(0);
		}
	}
}

char *str_get(char* str,int size)
{
    fgets(str,size,stdin);
    for(int i=0;i<size;i++)
    {
        if(str[i] == '\n')
        {
            str[i] = 0;
            return str;
        }
    }
    return str;
}

void _reserveId(unsigned int book_id)
{
	int ret = service.reserveBook(book_id);
	if(ret == -1 ) 
	{
		cout << "未找到这本书" << endl;
	}
	else if(-2 == ret )
	{
		cout << "已预约这本书" << endl;
	}
	else
	{
		int num = ret/1000;
		int position = ret%1000;
		cout << "预定成功!此书余量:" << num << " 预定排号:" << position << endl;
		if(num >= position)
		{
			cout << "请于一天内前往借书" << endl;
		}
	}
    get_char();
    return;
}

void reserveId(void)
{
	system("clear");
	cout << "请输入书号:" ;
	unsigned int book_id = 0;
	cin >> book_id;
	getch();
	_reserveId(book_id);
}

void reserveName(void)
{
	system("clear");
	cout << "请输入书名:" ;
	string book_name;
	cin >> book_name;
	getch();
	vector<BookInfo> vecBook = service.reserveBook(book_name.c_str());
	if(vecBook.size() == 0) 
	{
		cout << "未找到这本书" << endl;
		get_char();
	}
	else if(vecBook.size() == 1)
	{
		_reserveId(vecBook.at(0).m_id);
	}
	else
	{
		while(1)
		{
			for(vector<BookInfo>::iterator it = vecBook.begin() ; it != vecBook.end();it++)
			{
                printf("书号:%u\t书名:%s\t作者:%s\t类别:%s\n",it->m_id,it->m_name.c_str(),it->m_author.c_str(),it->m_type.c_str());
			}
			cout << "输入q返回上一层" << endl;
			cout << "请输入要预定的书号:";
			string book_id;
			cin >> book_id;
			if(0 == strcmp("q",book_id.c_str())) return ;
			_reserveId(atoi(book_id.c_str() ) );
            return;
		}
	}
	return;
}

//预订图书：输入书号或书名预订图书，预订成功然后返回前排在第几位
void ClientServiceView::reserveBook(void)
{
	while(1)
	{
		system("clear");
		cout << "[1]按书号预定" << endl;
		cout << "[2]按书名预定" << endl;
		cout << "[q]返回上一层" << endl;
		switch(getch())
		{
			case '1' : reserveId();break;
			case '2' : reserveName();break;
			case 'q' : return ;
		}
        AccountData m;
        m.save(CurAccount);
	}
}

//查询个人信息：直接显示个人信息，此处可以修改部分个人信息
void ClientServiceView::queryUser(void)
{
    AccountData m;
    Account* acc = m.load(CurAccount.m_id);
    CurAccount = *acc;
    delete acc;
	while(1)
	{
		system("clear");
		printf("昵称:%s\n",CurAccount.m_name.c_str() );
		cout << "ID:" << CurAccount.m_id << endl;
		printf("注册时间:%d/%d/%d\n",CurAccount.m_regTime.tm_year+1900,CurAccount.m_regTime.tm_mon+1,CurAccount.m_regTime.tm_mday);
		cout << "余额:" << CurAccount.m_money << endl;
		cout << "押金:" << CurAccount.m_deposit << endl;
		cout << "预约记录:" <<  CurAccount.m_reserve.size() << endl;
		time_t timep;
		time(&timep);
		unsigned int i=0;
		if(i<CurAccount.m_reserve.size())
		{
			printf("预约时间\t书号\t预约状态\n");
		}
		for(;i<CurAccount.m_reserve.size();i++)
		{
			printf("%d/%d/%d\t",CurAccount.m_reserve.at(i).m_time.tm_year+1900,CurAccount.m_reserve.at(i).m_time.tm_mon+1,CurAccount.m_reserve.at(i).m_time.tm_mday);
			printf("%d\t",CurAccount.m_reserve.at(i).m_bookId);
			struct tm acc_tm= CurAccount.m_reserve.at(i).m_time;
			time_t acc_time = mktime(&acc_tm);
			if(timep - acc_time < 60)
			{
				cout  << "时效内" << endl;
			}
			else
			{
				cout << "已过期" << endl;
			}
		}
		cout << "借书记录:" <<  CurAccount.m_record.size() << endl;
		if(i<CurAccount.m_record.size() )
		{
			printf("编号\t书名\t书号\t借书时间\t\t状态\n");
		}
		for(unsigned int i=0;i<CurAccount.m_record.size();i++)
		{
			printf("%d\t%s\t",CurAccount.m_record[i].m_id,CurAccount.m_record[i].m_bookName.c_str());
			printf("%d\t",CurAccount.m_record[i].m_bookId);
			printf("%d/%d/%d %d:%d:%d\t",
			CurAccount.m_record[i].m_broTime.tm_year+1900,
			CurAccount.m_record[i].m_broTime.tm_mon+1,
			CurAccount.m_record[i].m_broTime.tm_mday,
			CurAccount.m_record[i].m_broTime.tm_hour-8,
			CurAccount.m_record[i].m_broTime.tm_min,
			CurAccount.m_record[i].m_broTime.tm_sec);
			printf("%s\n",CurAccount.m_record[i].m_isReturn?"已归还":"未归还");
		}
		get_char();
		return ;
	}
}


void addToList(Book* book)
{
	if(0 == CurAccount.m_vecList.size())
	{
		system("clear");
		cout << "暂无书单" << endl;
		cout << "[+]创建新书单" << endl;
		cout << "[q]返回上一层" << endl;
		char ch = getch() ;
		if(ch == '+')
		{
			cout << "输入书单名:";
			string name;
			cin >> name;
			getch();
			unsigned int list_id = generator_BookListId();
			service.createBookList(list_id,name.c_str());
			cout << "创建成功,生成书单号:" << list_id << endl;
			get_char();
		}
		else if(ch == 'q')
		{
			return ;
		}
	}
	while(0 != CurAccount.m_vecList.size())
	{
		unsigned int i = 0;
		system("clear");
		printf("编号\t书单号\t书单名\n");
		for(vector<unsigned int>::iterator it=CurAccount.m_vecList.begin();it !=CurAccount.m_vecList.end();it++)
		{
			BookList* list = BookListLoad(*it);
			if(list == NULL)
			{
				CurAccount.m_vecList.erase(it);
				continue;
			}
			delete list;
		}
		for(;i<CurAccount.m_vecList.size();i++)
		{
			BookList* list = BookListLoad(CurAccount.m_vecList.at(i));
			printf("%d\t%u\t%s\n",i+1,list->m_id,list->m_name.c_str());
			delete list;
		}
		cout << "[+]创建新书单" << endl;
		cout << "[q]返回上一层" << endl;
		cout << "[回车]选择书单" << endl;
		switch(getch())
		{
			case '\n' :
				{
					cout << "编号:" ;
					unsigned int list_id = 0;
					cin >> list_id;
					getch();
					if(list_id >= i && list_id<=0) 
					{
						cout << "编号错误" << endl;
						break;
					} 
					BookList* list = BookListLoad(CurAccount.m_vecList.at(list_id-1));
					if(list->mapBookInfo.find(CurAccount.m_vecList.at(list_id-1)) != list->mapBookInfo.end() )
					{
						cout << "此书已存在书单中" << endl;
						getch();
						break;
					}
					list->addBook(book->m_id);
					BookListSave(*list);
					delete list;
					cout << "添加成功" << endl;
					get_char();
				}
				break;
			case '+'  : 
				{
					cout << "输入书单名:";
					string name;
					cin >> name;
					getch();
					unsigned int list_id = generator_BookListId();
					service.createBookList(list_id,name.c_str());
					cout << "创建成功,生成书单号:" << list_id << endl;
					sleep(1);
				}
				break;
			case 'q' : return;
		}
		
		
	}
}

void addComment(Book* book)
{
    cout << "请输入评论内容:" << endl;
    char syn1[2048];
    char* syn=str_get(syn1,sizeof(syn1));
	cout << "请对本书评分:" << endl;
    cout << "[-]<--  -->[+] 回车确定" << endl;
	unsigned int score = 4;
	while(1)
	{
		bool flag = false;
		switch(score)
		{
            case 1 : cout << "★☆☆☆☆"; break;
            case 2 : cout << "★★☆☆☆"; break;
            case 3 : cout << "★★★☆☆"; break;
            case 4 : cout << "★★★★☆"; break;
            case 5 : cout << "★★★★★"; break;
		}
		switch(getch())
		{
			case 186 :  if(score!=1) score--;break;
			case 185 :  if(score!=5) score++;break;
			case '\n' : flag= true; break;
		}
		if(flag) break;
		for(int i=0;i<5;i++) printf("\b \b");
	}
	double sum_score = book->m_score*book->m_sco_num;
	sum_score += score;
	book->m_numCom++;
	++book->m_sco_num;
	book->m_score = sum_score/book->m_sco_num;
	time_t t;
	time(&t);
	struct tm* tp = localtime(&t);
    Comment new_com(CurAccount.m_name.c_str(),*tp,score,syn,book->m_numCom);
	book->addComment(new_com);
	BookServiceData m;
	m.save(*book);
    cout << "\n评论成功\n" <<endl;
    get_char();
}

void addScore(Book* book)
{
	cout << "请对本书评分:" << endl;
	cout << "[-]<--  -->[+] 回车确定" << endl;
	unsigned int score = 4;
	while(1)
	{
		bool flag = false;
		switch(score)
		{
			case 1 : cout << "★☆☆☆☆"; break;
			case 2 : cout << "★★☆☆☆"; break;
			case 3 : cout << "★★★☆☆"; break;
			case 4 : cout << "★★★★☆"; break;
			case 5 : cout << "★★★★★"; break;
		}
		switch(getch())
		{
			case 186 :  if(score!=1) score--;break;
			case 185 :  if(score!=5) score++;break;
			case '\n' : flag= true; break;
		}
		if(flag) break;
		for(int i=0;i<5;i++) printf("\b \b");
	}
	double sum_score = book->m_score*book->m_sco_num;
	sum_score += score;
	book->m_numCom++;
	++book->m_sco_num;
	book->m_score = sum_score/book->m_sco_num;
	BookServiceData m;
	m.save(*book);
}

void reserveBook(Book* book)
{
	_reserveId(book->m_id);
}

void recommendBook(Book* book)
{
	book->m_recom++;
	BookServiceData m;
	m.save(*book);
	cout << "推荐成功" << endl;
    get_char();
}

void displayBook(Book* book)// 显示图书信息
{
	while(1)
	{
        system("clear");
        cout << "书名:" << book->m_name;		printf("\033[%d;%dH|菜单\n", (1), (45));
        cout << "作者:" << book->m_author;	printf("\033[%d;%dH|[1]添加到书单\n", (2), (45));
        cout << "书号:" << book->m_id;	 	printf("\033[%d;%dH|[2]评论 [3]评分\n", (3), (45));
        cout << "类别:" << book->m_type;		printf("\033[%d;%dH|[4]预约 [5]推荐\n", (4), (45));
        cout << "剩余数量:" << book->m_amout;	printf("\033[%d;%dH|[q]返回\n", (5), (45));
        cout << "总数:" << book->m_total << endl;
        cout << "评分:";
        int score = book->m_score*10;
        switch(score)
        {
            case  0 ... 15 : cout << "★☆☆☆☆" << endl; break;
            case 16 ... 25 : cout << "★★☆☆☆" << endl; break;
            case 26 ... 35 : cout << "★★★☆☆" << endl; break;
            case 36 ... 45 : cout << "★★★★☆" << endl; break;
            case 46 ... 50 : cout << "★★★★★" << endl; break;
        }
        cout << "评分人数:" << book->m_sco_num << endl;
        cout << "推荐数:" << book->m_recom << endl;
        cout << "上架状态:" << book->m_isShelf << endl;
        cout << "简介:" << book->m_syn << endl;

        cout << "评论数:" << book->m_vecCom.size() << endl;

        //vector<Comment> m_vecCom; //评论
        for(unsigned int i=0; i<book->m_vecCom.size();i++)
        {
            cout << "——————————————————————————————" << endl;
            cout << i+1 << " 昵称：" << book->m_vecCom.at(i).m_name << " " << 1900+book->m_vecCom.at(i).m_time.tm_year << "/"
                    << 1+book->m_vecCom.at(i).m_time.tm_mon << "/" << book->m_vecCom.at(i).m_time.tm_mday << " "
                    << book->m_vecCom.at(i).m_time.tm_hour << ":" << book->m_vecCom.at(i).m_time.tm_min << ":"
                    << book->m_vecCom.at(i).m_time.tm_sec << " 评分:";
                    score = book->m_vecCom.at(i).m_score*10;
                    switch(score)
                    {
                        case  0 ... 15 : cout << "★☆☆☆☆" << endl; break;
                        case 16 ... 25 : cout << "★★☆☆☆" << endl; break;
                        case 26 ... 35 : cout << "★★★☆☆" << endl; break;
                        case 36 ... 45 : cout << "★★★★☆" << endl; break;
                        case 46 ... 50 : cout << "★★★★★" << endl; break;
                    }
            cout << "内容:" << book->m_vecCom.at(i).m_content << endl;
        }
        cout << "请输入:" << endl;

        switch(getch())
        {
            case '1' : addToList(book);break;
            case '2' : addComment(book);break;
            case '3' : addScore(book);break;
            case '4' : reserveBook(book);break;
            case '5' : recommendBook(book);break;
            case 'q' :
                {
                    BookServiceData m;
                    m.save(*book);
                    delete book;
                    return ;
                }
        }
	}
}

void queryBookId(void)
{
	cout << "请输入书号:" ;
	unsigned int book_id;
	cin  >> book_id;
	getch();
	Book* book = service.queryBook(book_id);
	if(book == NULL)
	{
		cout << "未找到这本书" <<  endl;
        get_char();
		return ;
	}
	else
	{
		displayBook(book);
	}
}


void queryBookName(void)
{
	cout << "请输入书名:" ;
	string book_name;
	cin  >> book_name;getchar();
	vector<BookInfo> vecBook = service.queryBook(book_name.c_str());
	if(vecBook.size() == 0) 
	{
		cout << "未找到这本书" << endl;
        get_char();
		return ;
	}
	else if(vecBook.size() == 1)
	{
		BookServiceData m;
		Book* book = m.load(vecBook.at(0).m_id);
		displayBook(book);
	}
	else
	{
		while(1)
		{
			for(vector<BookInfo>::iterator it = vecBook.begin() ; it != vecBook.end();it++)
			{
				printf("书号:%u书名:%s作者:%s类别:%s\n",it->m_id,it->m_name.c_str(),it->m_author.c_str(),it->m_type.c_str());
			}
			cout << "输入q返回上一层" << endl;
			cout << "请输入要查询的书号:";
			string book_id;
			cin >> book_id;
			if(0 == strcmp("q",book_id.c_str())) return ;
		}
	}
}

//查询图书信息：输入书号或书名查询图书、输入图书名模糊查找
void ClientServiceView::queryBook(void)
{
	while(1)
	{
		system("clear");
		cout << "[1]按书号查找" << endl;
		cout << "[2]按书名查找" << endl;
		cout << "[q]返回上一层" << endl;
		switch(getch())
		{
			case '1' : queryBookId();break;
			case '2' : queryBookName();break;
			case 'q' : return;
		}
	}
}


void displayTypeBook(const char* book_type)
{
	int count = 0;
	unsigned int pages = 0;
	system("clear");
	vector<BookInfo> vecBookInfo;
	for(map<unsigned int , BookInfo>::iterator it = BookIndex.mapBookInfo.begin(); it != BookIndex.mapBookInfo.end(); it++ )
	{
		if(0 == strcmp(book_type,"ALL") || 0 == it->second.m_type.compare(book_type))
		{
			vecBookInfo.push_back(it->second);
		}
	}
	if(vecBookInfo.size() == 0)
	{
		cout << "暂无该类的书" << endl;
		cout << "按任意键返回" << endl;
		getch();
		return;
	}
	count = vecBookInfo.size();
	unsigned int last_pages = count/10;
	while(1)
	{
		system("clear");
		printf("书号\t\t 书名\t\t\t\t 作者\t\t     类别\n");
		for(unsigned int i=pages*10;i< pages*10+10 && i<vecBookInfo.size(); i++)
		{
			printf("\033[%d;%dH", (i%10+2), (0));
			printf("%d\t\t",vecBookInfo.at(i).m_id);
			printf("《%s》\t\t",vecBookInfo.at(i).m_name.c_str());
			printf("\033[%d;%dH", (i%10+2), (50));
			printf("%s\t\t",vecBookInfo.at(i).m_author.c_str());
			printf("\033[%d;%dH", (i%10+2), (70));
			printf("%s\n",vecBookInfo.at(i).m_type.c_str());
		}
		cout << "<--上一页 "<< pages+1 << "/" << last_pages+1<< " 下一页-->" ;
		if(pages == last_pages)
		{
			cout << "  已是最后一页";
		}
		cout << endl;
		cout << "[q]返回上一层"<< endl;
		cout << "按回车输入书号" << endl;
		unsigned int book_id = 0;
		switch(getch())
		{
			//右
			case 185 : if(pages != last_pages)pages++;break; //右
			case 186 : if(0!=pages)
						{pages--;} break; //左
			case 'q' : return ;
			case '\n' : 
			{
				cout << "书号:";
				cin >> book_id ;getch(); break;
			}
		}
		if(book_id != 0)
		{
			Book* book = service.queryBook(book_id);
			if(NULL != book) 
			{
				displayBook(book);
			}
			else
			{
				cout << "书号错误" << endl;
				get_char();
			}
		}
	}
}

//浏览所有图书：使用目录列出所有图书，可以翻页，输入书号可以查询图书详细信息，可根据分类浏览，在图书详细信息里可以对图书进行评论和打分
void ClientServiceView::listAllBook(void )	
{
	while(1)
	{
		system("clear");
		cout << "[1]浏览所有图书" << endl;
		cout << "[2]小说" << endl;
		cout << "[3]文学" << endl;
		cout << "[4]童书" << endl;
		cout << "[5]传记" << endl;
		cout << "[6]历史" << endl;
		cout << "[7]考试" << endl;
		cout << "[8]科技" << endl;
		cout << "[9]哲学" << endl;
		cout << "[0]管理" << endl;
		cout << "[q]返回上一层" << endl;
		switch(getch())
		{
			case '1' : displayTypeBook("ALL");break;
			case '2' : displayTypeBook("小说");break;
			case '3' : displayTypeBook("文学");break;
			case '4' : displayTypeBook("童书");break;
			case '5' : displayTypeBook("传记");break;
			case '6' : displayTypeBook("历史");break;
			case '7' : displayTypeBook("考试");break;
			case '8' : displayTypeBook("科技");break;
			case '9' : displayTypeBook("哲学");break;
			case '0' : displayTypeBook("管理");break;
			case 'q' : return;
		}
	}
}

void displayBookList(unsigned int list_id)
{
	int count = 0;
	unsigned int pages = 0;
	BookList* list = BookListLoad(list_id);
	if(list== NULL ) return ;
	system("clear");
	vector<BookInfo> vecBookInfo;
	for(map<unsigned int , BookInfo>::iterator it = list->mapBookInfo.begin(); it != list->mapBookInfo.end(); it++ )
	{
		vecBookInfo.push_back(it->second);
	}
	delete list;
	if(vecBookInfo.size() == 0)
	{
		cout << "暂无图书" << endl;
		get_char();	
		return;
	}
	count = vecBookInfo.size();
	unsigned int last_pages = count/10;
	while(1)
	{
		system("clear");
		printf("书号\t\t 书名\t\t\t\t 作者\t\t     类别\n");
		for(unsigned int i=pages*10;i< pages*10+10 && i<vecBookInfo.size(); i++)
		{
			printf("\033[%d;%dH", (i%10+2), (0));
			printf("%d\t\t",vecBookInfo.at(i).m_id);
			printf("《%s》\t\t",vecBookInfo.at(i).m_name.c_str());
			printf("\033[%d;%dH", (i%10+2), (50));
			printf("%s\t\t",vecBookInfo.at(i).m_author.c_str());
			printf("\033[%d;%dH", (i%10+2), (70));
			printf("%s\n",vecBookInfo.at(i).m_type.c_str());
		}
		cout << "<--上一页 "<< pages+1 << "/" << last_pages+1<< " 下一页-->" ;
		if(pages == last_pages)
		{
			cout << "已是最后一页";
		}
		cout << endl;
		cout << "[q]返回上一层"<< endl;
		cout << "按回车输入书号" << endl;
		unsigned int book_id = 0;
		switch(getch())
		{
			//右
			case 185 : if(pages != last_pages)pages++;break; //右
			case 186 : if(0!=pages)
						{pages--;} break; //左
			case 'q' : return ;
			case '\n' : 
			{
				cout << "书号:";
				cin >> book_id ;getch(); break;
			}
		}
		if(book_id != 0)
		{
			Book* book = service.queryBook(book_id);
			if(NULL != book) 
			{
				displayBook(book);
			}
			else
			{
				cout << "书号错误" << endl;
				cout << "按任意键返回" << endl;
				getch();
			}
		}
	}
}

bool delMyList(unsigned int list_id,vector<unsigned int>& m_vecList)
{
	for(vector<unsigned int>::iterator it=m_vecList.begin();it !=m_vecList.end();it++)
	{
		if(*it == list_id)
		{
			CurAccount.m_vecList.erase(it);
			return true;
		}
	}
	return false;
}

void myAllBookList(void)
{
	
	if(0 == CurAccount.m_vecList.size())
	{
		system("clear");
		cout << "暂无书单" << endl;
		cout << "[q]返回上一层" << endl;
		cout << "[+]创建新书单" << endl;
		char ch = getch() ;
		if(ch == '+')
		{
			cout << "输入书单名:";
			string name;
			cin >> name;
			getch();
			unsigned int list_id = generator_BookListId();
			service.createBookList(list_id,name.c_str());
			cout << "创建成功,生成书单号:" << list_id << endl;
			AccountData accdata;
			accdata.save(CurAccount);
			sleep(1);
		}
		else if(ch == 'q')
		{
			return ;
		}
	}
	while(0 != CurAccount.m_vecList.size())
	{
		system("clear");
		printf("书单号\t书单名\n");
		for(vector<unsigned int>::iterator it=CurAccount.m_vecList.begin();it !=CurAccount.m_vecList.end();it++)
		{
			BookList* list = BookListLoad(*it);
			if(list == NULL)
			{
				CurAccount.m_vecList.erase(it);
				continue;
			}
			printf("%u\t%s\n",list->m_id,list->m_name.c_str());
			delete list;
		}
		cout << "按回车输入书单号" << endl;
		cout << "按q返回上一层" << endl;
		cout << "[+]创建新书单" << endl;
		cout << "[-]删除书单" << endl;
		switch(getch())
		{
			case '\n' :
				{
					cout << "书单号:" ;
					unsigned int list_id = 0;
					cin >> list_id;
					displayBookList(list_id);
				}
				break;
			case '+'  : 
				{
					cout << "输入书单名:";
					string name;
					cin >> name;
					getch();
					unsigned int list_id = generator_BookListId();
					service.createBookList(list_id,name.c_str());
					cout << "创建成功,生成书单号:" << list_id << endl;
					sleep(1);
				}
				break;
			case 'q' : 
			{
				AccountData accdata;
				accdata.save(CurAccount);
				return;
			}break;
			case '-' : 
			{
				cout << "书单号:" ;
				unsigned int list_id = 0;
				cin >> list_id;
				getch();
				if(delMyList(list_id,CurAccount.m_vecList) )
				{
					cout << "删除成功" << endl;
					AccountData accdata;
				accdata.save(CurAccount);
				}
				else
				{
					cout << "删除失败，无此书单" << endl;
				}
				getch();
			}
		}
	}
}
void myCollectionBookList(void)
{
	if(0 == CurAccount.m_collection.size())
	{
		system("clear");
		cout << "暂无书单" << endl;
		cout << "[q]返回上一层" << endl;
		cout << "[+]添加新书单" << endl;
		char ch = getch();
		if(ch == '+')
		{
			cout << "输入书单号:";
			unsigned int list_id = 0;
			cin >> list_id;
			getch();
			BookList* listp = BookListLoad(list_id);
			if(listp == NULL )
			{
				cout << "此书单不存在" << endl;
				getch();
			}
			else
			{
				CurAccount.m_collection.push_back(listp->m_id);
				cout << "添加成功" << endl;
				AccountData accdata;
				accdata.save(CurAccount);
				delete listp;
				getch();
			}
			
		}
		else if(ch == 'q')
		{
			return;
		}
	}
	while(0 != CurAccount.m_collection.size())
	{
		system("clear");
		printf("书单号\t书单名\n");
		for(vector<unsigned int>::iterator it=CurAccount.m_collection.begin();it !=CurAccount.m_collection.end();it++)
		{
			BookList* list = BookListLoad(*it);
			if(list == NULL)
			{
				CurAccount.m_collection.erase(it);
				continue;
			}
			printf("%u\t%s\n",list->m_id,list->m_name.c_str());
			delete list;
		}
		cout << "按回车输入书单号查看" << endl;
		cout << "[q]返回上一层" << endl;
		cout << "[+]添加新书单" << endl;
		cout << "[-]删除书单" << endl;
		switch(getch())
		{
			case '\n' :
				{
					cout << "书单号:" ;
					unsigned int list_id = 0;
					cin >> list_id;
					getch();
					displayBookList(list_id);
				}
				break;
			case '+'  : 
				{
					cout << "输入书单号:";
					unsigned int list_id = 0;
					cin >> list_id;
					getch();
					BookList* listp = BookListLoad(list_id);
					if(listp == NULL )
					{
						cout << "此书单不存在" << endl;
						getch();
					}
					else
					{
						CurAccount.m_collection.push_back(listp->m_id);
						cout << "添加成功" << endl;
						AccountData accdata;
						accdata.save(CurAccount);
						delete listp;
						getch();
					}
					break;
				}
				
			case 'q' : return;
			case '-' :
			{
				cout << "书单号:" ;
				unsigned int list_id = 0;
				cin >> list_id;
				getch();
				if(delMyList(list_id,CurAccount.m_vecList) )
				{
					cout << "删除成功" << endl;
					AccountData accdata;
				accdata.save(CurAccount);
				}
				else
				{
					cout << "删除失败，无此书单" << endl;
				}
				getch();
			}break;
		}
	}
}

void ClientServiceView::myBookList(void)
{
	while(1)
	{
		system("clear");
		cout << "[1]我的书单" << endl;
		cout << "[2]收藏的书单" << endl;
		cout << "[q]返回上一层" << endl;
		switch(getch())
		{
			case '1' : myAllBookList();break;
			case '2' : myCollectionBookList();break;
			case 'q' : return;
		}
		AccountData m;
        m.save(CurAccount);
	}
}
